package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.result.Result;
import com.example.common.result.YiFeiException;
import com.example.entity.hz.MOCTA;
import com.example.entity.vo.MoctaQueryVo;
import com.example.entity.vo.SfcteQueryVo;
import com.example.mapper.MoctaMapper;
import com.example.service.MoctaService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiangPandeng
 * @since 2024-02-28
 */
@Service
public class MoctaServiceImpl extends ServiceImpl<MoctaMapper, MOCTA> implements MoctaService {

    @Resource
    private MoctaMapper moctaMapper;

    @Override
    public Result queryMoctaQueryVo(Integer current, Integer size, MoctaQueryVo moctaQueryVo) {
        try{
            Map<String,Object> map = new HashMap<>();
            PageHelper.startPage(current,size);
            List<MoctaQueryVo> moctaQueryVoList = this.moctaMapper.queryMoctaQueryVo(moctaQueryVo);
            PageInfo<MoctaQueryVo> moctaQueryVoPageInfo = new PageInfo<>(moctaQueryVoList);
            map.put("pages", moctaQueryVoPageInfo.getPages());
            map.put("total", moctaQueryVoPageInfo.getTotal());
            map.put("list", moctaQueryVoPageInfo.getList());
            return Result.success(map);
        }catch (Exception e){
            throw new YiFeiException(500,"查询工单情况分页发生异常"+e.getMessage());
        }
    }

    @Override
    public Result querySfcte(Integer current, Integer size, SfcteQueryVo sfcteQueryVo) {
        try{
            Map<String,Object> map = new HashMap<>();
            PageHelper.startPage(current,size);
            List<SfcteQueryVo> sfcteQueryVoList = this.moctaMapper.querySfcte(sfcteQueryVo);
            PageInfo<SfcteQueryVo> sfcteQueryVoPageInfo = new PageInfo<>(sfcteQueryVoList);
            map.put("pages", sfcteQueryVoPageInfo.getPages());
            map.put("total", sfcteQueryVoPageInfo.getTotal());
            map.put("list", sfcteQueryVoPageInfo.getList());
            return Result.success(map);
        }catch (Exception e){
            throw new YiFeiException(500,"派工单查询分页发生异常"+e.getMessage());
        }
    }

    @Override
    public Result queryMocTaIPage(Integer current, Integer size) {
        try{
            Map<String,Object> map = new HashMap<>();
            PageHelper.startPage(current,size);
            List<MOCTA> moctaList = this.moctaMapper.selectList(null);
            PageInfo<MOCTA> moctaPageInfo = new PageInfo<>(moctaList);
            map.put("pages", moctaPageInfo.getPages());
            map.put("total", moctaPageInfo.getTotal());
            map.put("list", moctaPageInfo.getList());
            return Result.success(map);
        }catch (Exception e){
            throw new YiFeiException(500,"查询工单分页发生异常"+e.getMessage());
        }
    }
}
